/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mxgraph.examples.swing;

/**
 *
 * @author somesh
 */
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
 
//Check open port in java
 
public class NetworkOpenPortExample {
    public static void main(String[] args) throws Exception {
        // Get the localhost address
        //InetAddress inetAddress = InetAddress.getByName("localhost");
        
        // Get the Hostname
        //String localhost = inetAddress.getHostName();
        // Check from 0 to 9999 port
        for (int port = 24; port <= 28; port++) {
            try {
                // Try to create the Socket on the port.
                // If you fail to create the Socket.
                // Socket is not open
                System.out.println("Welcome");
                Socket socket = new Socket();
                SocketAddress endpoint = new InetSocketAddress( "10.200.3.16", port );
                //socket.connect"10.200.3.12"+port, 1000);
                socket.connect(endpoint, 1000);
                String message = port + " is open in 10.200.3.14" ;
                System.out.println(message);
                socket.close();
            } catch (IOException e) {
                // If fail to create Socket,
                // The port is not open
                String message = port + " is not open in ";
                System.out.println(message);
            }
        }
    }
}